package volkov.ja.pages;

import org.openqa.selenium.TimeoutException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.WebDriverWait;

import sun.reflect.ReflectionFactory.GetReflectionFactoryAction;
import volkov.ja.util.PageUtils;
import volkov.ja.util.TracingWebDriver;

/*
 * Abstract class representation of a Page in the UI. Page object pattern
 * 
 * @author Sebastiano Armeli-Battana
 */
public abstract class Page {

	protected PageManager pages;

	// protected WebDriver driver;
	// protected WebDriverWait wait;
	// protected PageUtils utils;

	/*
	 * Constructor injecting the PageManager
	 * 
	 * @param webDriver
	 */
	public Page(PageManager pages) {
		this.pages = pages;
		// driver = pages.getWebDriver();
		// wait = new WebDriverWait(driver, 10);
		// utils = new PageUtils(pages.getWebDriver());
	}

	public WebDriver getWebDriver() {
		// return driver;
		return pages.getWebDriver();
	}

	public String getTitle() {
		// return driver.getTitle();
		return pages.getWebDriver().getTitle();
	}

	public Page ensurePageLoaded() {
		return this;
	}

	public String getPageRelativeUrl() {
		return "";
	};

	public boolean waitPageLoaded() {
		try {
			ensurePageLoaded();
			return true;
		} catch (TimeoutException to) {
			return false;
		}
	}
}
